using UnityEngine;

public static class TransformExtensions
{
	public static void CreateParentAndCopyTransform(this Transform transform)
	{
		Vector3 position = transform.position;
		Vector3 localScale = transform.localScale;
		GameObject gameObject = new GameObject("Root" + transform.gameObject.name);
		gameObject.transform.SetParent(transform.parent);
		gameObject.transform.position = position;
		gameObject.transform.localScale = localScale;
		transform.SetParent(gameObject.transform);
		transform.localPosition = Vector3.zero;
		transform.localScale = Vector3.one;
	}

	public static void StretchInBothAxis(this RectTransform rectTransform)
	{
		rectTransform.anchorMin = Vector2.zero;
		rectTransform.anchorMax = Vector2.one;
		rectTransform.pivot = Vector2.one / 2f;
		rectTransform.sizeDelta = Vector2.zero;
	}

	public static void SetParentAndCopyTransform(this Transform child, Transform parent)
	{
		Vector3 localPosition = child.localPosition;
		Vector3 localScale = child.localScale;
		Quaternion localRotation = child.localRotation;
		child.SetParent(parent);
		child.localPosition = localPosition;
		child.localScale = localScale;
		child.localRotation = localRotation;
	}
}
